//
//  BangdinTableViewCell.m
//  DA_V
//
//  Created by 小青年 on 15/10/18.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "BangdinTableViewCell.h"
#import "InterFace.h"
#import "UIButton+WebCache.h"
#import "UIViewAdditions.h"
@implementation BangdinTableViewCell

- (void)awakeFromNib {
    // Initialization code
}



- (void)sdataUI:(id)sender{

    int btnTag = 0;
    NSDictionary *dic = sender;
    NSArray *bankArry = dic[@"BankList"];
    self.arr = [NSMutableArray arrayWithArray:bankArry];
    
    UILabel *choose = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH/2.0-20, 20)];
    choose.text = [NSString stringWithFormat:@"单笔限额%@",dic[@"SingleLimit"]];
    choose.textColor  = [UIColor blackColor];
    choose.textAlignment = NSTextAlignmentLeft;
    choose.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:choose];
    
    UILabel *choose2 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2.0-10, 0, SCREEN_WIDTH/2.0-20, 20)];
    choose2.text = [NSString stringWithFormat:@"每日限额%@",dic[@"DayLimit"]];
    choose2.textColor  = [UIColor blackColor];
    choose2.textAlignment = NSTextAlignmentRight;
    choose2.font = [UIFont systemFontOfSize:14];

    [self.contentView addSubview:choose2];

    NSInteger zCount = bankArry.count/3;
    NSLog(@"%lu",bankArry.count%3);
    if (([bankArry count]%3) != 0) {
        zCount += 1;
    }
    
    for (int j = 0; j< zCount; j++) {
        
        int num = 0;
        if (bankArry.count == 1) {
            num = 1;
        } else if (bankArry.count == 2){
            num = 2;
        } else{
            
            num = 3;
        }
        
        for (int h = 0; h < num; h++) {
            
            //
            NSDictionary *dica = bankArry[btnTag];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            if (SCREEN_WIDTH == 320) {
                btn.frame = CGRectMake(10+102.5*h,choose.bottom+5+j*40 , 95, 35);
            }
            [btn.layer setBorderWidth:1.0f];
            [btn.layer setBorderColor:[UIColor grayColor].CGColor];
            [btn sd_setBackgroundImageWithURL:[NSURL URLWithString:dica[@"LogoPath"]] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
            [self.contentView addSubview:btn];
            btn.tag = btnTag +1;
            btnTag++;
            if (btnTag == [bankArry count]) {
                break;
            }
        }
    }


}
- (void)clickUser:(UIButton *)sender{
    NSDictionary *dic = self.arr[sender.tag-1];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"bankBut" object:nil userInfo:@{@"BankId":dic[@"BankID"],@"button":sender}];
    
    NSLog(@"BankId=====%@",dic[@"BankID"]);
}
@end
